Script hook
Over the years, Cadmatic has created a number of script hooks that allow the user organizations to interface application events that normally cannot be interfaced. These actions are automated to occur whenever a user invokes a specific command in a specific context, but only if the given script hook is present in the environment. For example, starting to create a new drawing or diagram can trigger a script hook to get the header data of the document from a Document Management System (DMS).
Originally, script hooks were separate files that Cadmatic distributed upon request, but now they are part of the software installation and managed via the COS databases. Be aware that if your environment still has old script hook files in PMS_HOME/opt/<app>/ScriptHooks.cnf folders, then they are going to be used instead of the ones in COS.
In the Project Environment dialog, the project administrator can take a script hook into use by creating a configuration for it and marking it as enabled. A script hook configuration that is created in the library database can be approved for use in projects.
In a script hook configuration, the administrator links the script hook to a matching function in a script that either Cadmatic or the user organization has created. Besides being able to automate specific background actions, script hooks have the benefit of allowing all the variables of the associated script to remain available after the script has stopped running (until the application session ends). Although each script hook has been written for a specific purpose, the variables which the associated scripts expose to the session can in principle be used by any other script function in the same script file.
This is how script hooks work in Plant Modeller, Piping Isometrics & Spools, and P&ID:
-
The user invokes a command that has the ability to use a script hook. The context where this happens is always predefined; only Cadmatic can add script hooks to application commands.
-
The script hook starts the script that is defined in the script hook configuration. If the script hook has input arguments, the script hook assigns the values of these input arguments in the associated script function.
-
The script runs its course and returns a value to the script hook. If the script function has output arguments, their values are assigned to the output arguments of the script hook.
-
The output arguments and the return value define the effect to the invoked command. For example, the command may continue execution with the new or changed data that it received from the script hook, or the script hook may indicate that the command should stop.
If the script hook is not found or is not enabled for use, then the invoked command simply does what it normally does.
Creating a script hook configuration
Create a script hook configuration that links a script hook to a script, so that triggering the script hook in the application will cause the associated script to be run.
As each script hook configuration is named after the script hook, there can be several configurations with the same name, but only one of them can be enabled at a time.
Prerequisites
-
COS contains a script (see Scripts) where a function has arguments that match those of the script hook. If you are working in the library database, also the script must be in the library database. If you are working in the project database, you can select the script from the library or the project database.
Do the following:
-
In the Project Environment dialog, in [library or project] > Resources > Script Hook, select New > Script Hook. The Script Hook Editor dialog opens.
-
In the Hook name fields, first select the application and then the application-specific script hook.
-
In the Script section, define how to use the script hook:
-
Script – Click Browse to select the script that the script hook is to run.
-
Function – Select the script function that the script hook is to interact with.
-
Enable – Select this option to enable the script hook.
-
-
Click OK.
Script hooks for Plant Modeller
These script hooks exist for the scripts of the Plant Modeller application.
Name |
Purpose |
Context |
Input arguments |
Input/Output arguments |
Output arguments |
Return values |
---|---|---|---|---|---|---|
Specifies the Object ID, the name, and the header data of the document to be checked in, and returns (possibly modified) header data to the script hook. |
Called when about to check in the active drawing or a new drawing, before saving the drawing locally. |
|
|
– |
|
|
Specifies the Object ID, the name, and the header data of the document to be checked in. |
Called when a user is trying to open a drawing for the first time, after the drawing has been converted from the old format to the current format. |
|
– |
– |
|
|
Specifies the Object ID, the name, and the header data of the document to be checked in. |
Called when checking in a drawing, after PmScH_AboutToCheckInDrawing has been called and a local save has been done. |
|
– |
– |
|
|
Specifies the index of the Standard Component to be deleted. |
Called when deleting a Standard Component that has user-defined associations. |
|
– |
– |
(no effect to the context) |
|
Checks which flanges in the pipeline specifications of the active pipeline are suitable in the current context (for example, based on pressure and temperature). |
Called in the following contexts (a–d), if the pipeline has the attribute "Execute flange validation" set to "Yes":
|
|
– |
– |
|
|
Specifies the name of the document to be deleted. |
Called when about to delete a drawing. |
|
– |
– |
|
|
Specifies the COS object type of the document object in question. Can be used to add context-menu commands to the document object browser. |
Called when opening an object browser to manage drawings of a specific type, such as Plant Modeller Drawings or Duct Main Documents. |
|
– |
– |
|
|
Gets header information for a new drawing. |
Called when about to create a new drawing. |
– |
– |
|
|
|
Customize the value of the weld ID attributes that are assigned to object connection points. |
Called when creating isometric groups, before the weld ID attribute is assigned to the object connection point. |
|
|
– |
|
|
Specifies the Object ID of the document to be published. |
Called when publishing a drawing. |
|
– |
– |
(no effect to the context) |
|
(This script hook is obsolete.) |
Called when moving a set of objects and some of them have user-defined associations. |
|
– |
– |
|
|
(This script hook is obsolete.) |
Called from the script extern PM_RELOCATION_ACCEPTED when relocating a set of objects has been accepted. |
– |
– |
– |
|
|
(This script hook is obsolete.) |
Called from the script extern PM_RELOCATION_REJECTED when relocating a set of objects has been rejected. |
– |
– |
– |
|
Script hooks for Piping Isometrics & Spools
These script hooks exist for the scripts of the Piping Isometrics & Spools application.
Name |
Purpose |
Context |
Input arguments |
Input/Output arguments |
Output arguments |
Return values |
---|---|---|---|---|---|---|
Specifies the Object ID, the name, and the header data of the document to be checked in. |
Called when about to check in an isometric drawing, before a local save. |
|
– |
– |
|
|
Specifies the Object ID, the name, and the header data of the document to be checked in. |
Called when checking in an isometric drawing, after PiScH_AboutToCheckInIsometricDrawing has been called and a local save has been done. |
|
– |
– |
|
|
Specifies the Object ID, the name, and the header data of the document to be checked in. |
Called when about to edit an isometric drawing. |
|
– |
– |
|
|
Specifies the COS object type of the document object in question. Can be used to add context-menu commands to the document object browser. |
Called when opening an object browser to manage isometric drawings. |
|
– |
– |
|
|
Specifies the Object ID of the document to be deleted. |
Called when about to delete an isometric drawing. |
|
– |
– |
|
|
Specifies the Object ID of the document to be published. |
Called when publishing an isometric drawing. |
|
– |
– |
(no effect to the context) |
Script hooks for P&ID
These script hooks exist for the scripts of the P&ID application.
Name |
Purpose |
Context |
Input arguments |
Input/Output arguments |
Output arguments |
Return values |
---|---|---|---|---|---|---|
Specifies the GUID, the name, and the header data of the diagram to be checked in. |
Called at the beginning of saving a diagram that is to be checked in. |
|
– |
– |
|
|
Specifies the GUID and the name of the diagram to be checked out. |
Called when about to check out a diagram. |
|
– |
– |
|
|
Specifies the GUID and the name of the diagram whose check-out is to be canceled. |
Called when about to cancel the check-out of a diagram. |
|
– |
– |
|
|
Specifies the GUID, the name, and the header data of the diagram to be checked in, and returns (possibly modified) header data to the script hook. |
Called when checking in a diagram, after PdScH_AboutToCheckOutDiagram has been called and a local save has been done. |
|
|
– |
|
|
Specifies the GUID, the name, and the header data of the diagram to be checked out, and returns (possibly modified) header data to the script hook. |
Called when checking out a diagram. |
|
|
– |
(no effect to the context) |
|
Specifies the GUID of the diagram to be deleted. |
Called when about to delete a diagram. |
|
– |
– |
|
|
Specifies the COS object type of the document object in question. Can be used to add context-menu commands to the document object browser. |
Called when opening an object browser to manage diagrams. |
|
– |
– |
|
|
Gets the header data for a new diagram and returns (possibly modified) header data and the name of the new diagram to the script hook. |
Called when about to create a new diagram. |
|
|
|
|
|
Specifies the GUID of the new diagram publication. |
Called after creating a new diagram publication. |
|
– |
– |
(no effect to the context) |